package org.example.browser;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebElement;


import static java.lang.Thread.sleep;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-06-02
 * Time:17:59
 * Text：控制浏览器前进和后退，以及滚动条
 */
public class sportTest {

    public static void main(String[] args) throws InterruptedException {
        //前进和后退Test1();
        //滚动条
        Test2();
    }


    private static void Test2() throws InterruptedException {
            ChromeOptions options = new ChromeOptions();
            options.setBinary("D:\\Chrome\\chrome.exe");
            options.addArguments("--remote-allow-origins=*");
            WebDriver driver = new ChromeDriver(options);
            driver.get("https://www.baidu.com");
            WebElement element = driver.findElement(By.xpath("//*[@id=\"kw\"]"));
            element.sendKeys("我爱Java");
            driver.findElement(By.cssSelector("#su")).click();
            sleep(3000);
        ((JavascriptExecutor)driver).executeScript("document.documentElement.scrollTop=10000");
    }
    private static void Test1() throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.setBinary("D:\\Chrome\\chrome.exe");
        options.addArguments("--remote-allow-origins=*");
        WebDriver driver = new ChromeDriver(options);
        driver.get("https://www.baidu.com");
        WebElement element = driver.findElement(By.xpath("//*[@id=\"kw\"]"));
        element.sendKeys("我爱Java");
        driver.findElement(By.cssSelector("#su")).click();

        sleep(3000);

        WebElement element2 = driver.findElement(By.xpath("//*[@id=\"kw\"]"));
        element2.clear();
        element2.sendKeys("我爱Java2");
        driver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        //返回
        driver.navigate().back();
        sleep(3000);
        driver.navigate().refresh();
        sleep(3000);
        //前进
        driver.navigate().forward();
    }
}
